package jjn.acwing;

import java.util.Scanner;

/**
 * @author Jiang Jining
 * @since 2023-09-10 16:07
 */
public class Acwing771 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            for (int i = 0; i < n; i++) {
                String line = sc.next();
                int count = 0;
                char c = line.charAt(0);
                for (int j = 0; j < line.length(); ) {
                    int k = j + 1;
                    while (k < line.length() && line.charAt(k) == line.charAt(j)) {
                        k++;
                    }
                    if (k - j > count) {
                        count = k - j + 1;
                        c = line.charAt(j);
                    }
                    j = k;
                }
                
                System.out.printf("%c %d\n", c, count);
            }
        }
    }
}
